package com.xsomnus.java_basic.cacheline;

/**
 * @author 叶小夏
 * @since 2019-08-27 16:38
 */
public class RingBufferTest {

    private static long[][] arr1 = new long[8][100000];


    private static long[][] arr2 = new long[100000][8];

    static {
        for (int i = 0; i < 8; i++) {
            for (int j = 0; j < 100000; j++) {
                arr1[i][j] = i*j;
            }
        }


        for (int i = 0; i < 100000; i++) {
            for (int j = 0; j < 8; j++) {
                arr2[i][j] = i*j;
            }
        }
    }


    public static void main(String[] args) {
       loop(arr1);
       loop(arr2);
    }

    public static void loop(long[][] arr) {
        long start = System.currentTimeMillis();
        int sum  = 0;
        for (long[] longs : arr) {
            for (long aLong : longs) {
                sum += aLong;
            }
        }
        long end = System.currentTimeMillis();
        System.out.println("sum = " + sum + "time cost " + (end-start));
    }
}
